<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get or set the resolution of the image</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.imagerectangle.html">« imagerectangle</a></li>
      <li style="float: right;"><a href="function.imagerotate.html">imagerotate »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.image.html">GD 和图像处理 函数</a></li>
    <li>Get or set the resolution of the image</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.imageresolution" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imageresolution</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">imageresolution</span> &mdash; <span class="dc-title">Get or set the resolution of the image</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.imageresolution-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imageresolution</strong></span>(<span class="methodparam"><span class="type"><a href="class.gdimage.html" class="type GdImage">GdImage</a></span> <code class="parameter">$image</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$resolution_x</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$resolution_y</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type">bool</span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imageresolution()</strong></span> allows to set and get the resolution of
   an image in DPI (dots per inch). If the optional parameters are <strong><code>null</code></strong>,
   the current resolution is returned as an indexed array. If only
   <code class="parameter">resolution_x</code> is not <strong><code>null</code></strong>, the horizontal and vertical resolution
   are set to this value. If none of the optional parameters are <strong><code>null</code></strong>, the horizontal
   and vertical resolution are set to these values, respectively.
  </p>
  <p class="para">
   The resolution is only used as meta information when images are read from and
   written to formats supporting this kind of information (curently PNG and
   JPEG). It does not affect any drawing operations. The default resolution
   for new images is 96 DPI.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.imageresolution-parameters">
  <h3 class="title">参数</h3>
  <dl>
   <dt>

<code class="parameter">image</code></dt>
<dd>
<p class="para">由图象创建函数(例如<span class="function"><a href="function.imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>)返回的 
<span class="classname"><a href="class.gdimage.html" class="classname">GdImage</a></span> 对象。</p></dd>

   
    <dt>
<code class="parameter">resolution_x</code></dt>

    <dd>

     <p class="para">
      The horizontal resolution in DPI.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">resolution_y</code></dt>

    <dd>

     <p class="para">
      The vertical resolution in DPI.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.imageresolution-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   When used as getter,
   it returns an indexed array of the horizontal and vertical resolution on
   success,  或者在失败时返回 <strong><code>false</code></strong>.
   When used as setter, it returns
   <strong><code>true</code></strong> on success,  或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>



 <div class="refsect1 changelog" id="refsect1-function.imageresolution-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">resolution_x</code> and <code class="parameter">resolution_y</code> are now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imageresolution-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="imageresolution.example.basic">
   <p><strong>示例 #1 Setting and getting the resolution of an image</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imageresolution</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">200</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">imageresolution</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">imageresolution</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">300</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">72</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">imageresolution</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; 200
    [1] =&gt; 200
)
Array
(
    [0] =&gt; 300
    [1] =&gt; 72
)
</pre></div>
   </div>
  </div>
 </div>


</div></div></div></body></html>